package com.yxy.controller.user;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.pojo.dto.NewsPageQueryDTO;
import com.yxy.pojo.vo.NewsVO;
import com.yxy.service.NewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userNewController")
@RequestMapping(RequestMapperConstant.USER_REQUEST_MAPPER + "new")
@Slf4j
public class NewController {

    @Autowired
    private NewsService newsService;

    /**
     * 分页查询资讯列表
     * @param newsPageQueryDTO
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult> pageQuery(NewsPageQueryDTO newsPageQueryDTO){
        log.info("分页查询资讯列表：{}", newsPageQueryDTO);
        PageResult pageResult = newsService.pageQuery(newsPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 添加访问量
     * @param newId
     * @return
     */
    @PutMapping("/addVisit/{newId}")
    public Result addVisit(@PathVariable int newId){
        log.info("添加访问量");
        newsService.addVisit(newId);
        return Result.success("");
    }

    /**
     * 查询资讯详情
     * @param newId
     * @return
     */
    @GetMapping("/getNewsById")
    public Result<NewsVO> getNewsById(int newId){
        log.info("查询资讯详情：{}", newId);
        NewsVO newsVO = newsService.getNewsById(newId);
        return Result.success("", newsVO);
    }
}
